﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

using LowLevelGraphics;
using LowLevelGraphics.ImageFormats;
using LowLevelGraphics.ImageFormats.SVG;
using LowLevelGraphics.Extractors;

using System.Drawing.Drawing2D;

namespace UnitTests
{
    /// <summary>
    /// 
    /// </summary>
    public partial class Form1 : Form
    {
        GraphicsPath graphicsPath = null;
        /// <summary>
        /// 
        /// Initializes a new instance of the <see cref="Form1"/> class.
        /// </summary>
        public Form1()
        {
            InitializeComponent();

            //DrawTestPath();

            this.pictureBox1.Paint += delegate(object sender, PaintEventArgs e)
            {
                if (graphicsPath != null)
                {
                    e.Graphics.FillRectangle(Brushes.Blue, e.ClipRectangle);
                    e.Graphics.FillPath(Brushes.White, graphicsPath);
                }
            };
        }

        /// <summary>
        /// Draws the test path.
        /// </summary>
        private void DrawTestPath()
        {
            PointF ptStart = new PointF(71.985614f, 631.52918f);

            graphicsPath = new GraphicsPath();
            //C 60.553114,631.52918 49.989054,625.43 44.272794,615.52918 
            graphicsPath.AddBezier(ptStart, new PointF(60.553114f, 631.52918f), new PointF(49.989054f, 625.43f), new PointF(44.272794f, 615.52918f));

            //C 38.556554,605.62833 38.556554,593.43 44.272794,583.52918 
            ptStart = new PointF(44.272794f, 615.52918f);
            graphicsPath.AddBezier(ptStart, new PointF(38.556554f, 605.62833f), new PointF(38.556554f, 593.43f), new PointF(44.272794f, 583.52918f));

            //L 348.84719,55.99085 
            graphicsPath.AddLine(new PointF(44.272794f, 583.52918f), new PointF(348.84719f, 55.99085f));

            ptStart = new PointF(348.84719f, 55.99085f);
            //C 354.56345,46.09002 365.12751,39.99084 376.56,39.99084 
            graphicsPath.AddBezier(ptStart, new PointF(354.56345f, 46.09002f), new PointF(365.12751f, 39.99084f), new PointF(376.56f, 39.99084f));

            //C 387.99251,39.99084 398.55659,46.09002 404.27283,55.99085 
            ptStart = new PointF(376.56f, 39.99084f);
            graphicsPath.AddBezier(ptStart, new PointF(387.99251f, 39.99084f), new PointF(398.55659f, 46.09002f), new PointF(404.27283f, 55.99085f));

            //L 708.84723,583.52918 
            ptStart = new PointF(404.27283f, 55.99085f);

            //C 714.56347,593.43 714.56347,605.62833 708.84723,615.52918 
            graphicsPath.AddBezier(ptStart, new PointF(714.56347f, 593.43f), new PointF(714.56347f, 605.62833f), new PointF(708.84723f, 615.52918f));

            ptStart = new PointF(708.84723f, 615.52918f);
            //C 703.13097,625.42999 692.56691,631.52918 681.13441,631.52918 
            graphicsPath.AddBezier(ptStart, new PointF(703.13097f, 625.42999f), new PointF(2.56691f, 631.52918f), new PointF(681.13441f, 631.52918f));

            ptStart = new PointF(681.13441f, 631.52918f);
            //L 71.985614,631.52918 
            graphicsPath.AddLine(ptStart, new PointF(71.985614f, 631.52918f));

            ptStart = new PointF(71.985614f, 631.52918f);
            graphicsPath.AddLine(new PointF(71.985614f, 631.52918f), ptStart);
            //z "
        }

        /// <summary>
        /// Handles the Click event of the cbTestCoocurrenceMatrix control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void cbTestCoocurrenceMatrix_Click(object sender, EventArgs e)
        {
            new CooccurrenceMatrixTest().TestCoocurrenceMatrix();
        }

        /// <summary>
        /// Handles the Click event of the button1 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void button1_Click(object sender, EventArgs e)
        {
            new CooccurrenceMatrixTest().Test2();
        }

        /// <summary>
        /// Handles the DoubleClick event of the pictureBox1 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void pictureBox1_DoubleClick(object sender, EventArgs e)
        {
            OpenFileDialog fd = new OpenFileDialog();
            if (fd.ShowDialog() != DialogResult.OK) return;

            this.pictureBox1.BackgroundImage = null;
            UnsafeBitmap bitmap = LoadPic(fd.FileName);
            bitmap.UnlockImage();
            this.pictureBox1.BackgroundImage = bitmap.InternalBitmap;

        }

        /// <summary>
        /// Loads the pic.
        /// </summary>
        /// <param name="sFile">The s file.</param>
        public UnsafeBitmap LoadPic(string sFile)
        {
            UnsafeBitmap bitmap = null;

            if (File.Exists(sFile))
            {
                bitmap = SVGReader.Create(sFile);
                this.pictureBox1.BackgroundImage = bitmap.InternalBitmap;
            }
            return bitmap;
        }
    }
}
